package top.dudu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.dudu.entity.ProductCategory;
import top.dudu.repository.ProductCategoryRepository;
import top.dudu.service.CategoryService;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 类目
 * @author 嘟嘟
 * @date 2020-7-16 , 0016 21:31
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    ProductCategoryRepository repository;

    @Override
    public ProductCategory findOne(Integer categoryId) {
        Optional<ProductCategory> byId = repository.findById(categoryId);
        if (byId.isPresent()) {
            return byId.get();
        }
        else return null;
    }

    @Override
    public List<ProductCategory> findAll() {
        return repository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
        return repository.findByCategoryTypeIn(Arrays.asList(1,2,3,4));
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return repository.save(productCategory);
    }
}
